home *** CD-ROM | disk | FTP | other *** search
/ Zoom 2 / Zoom - Release 2 (1996)(Active Software)[!].iso / texts / arexxguide / extras / arx_makenodelist.rexx < prev    next >
OS/2 REXX Batch file  |  1994-03-24  |  6KB  |  191 lines

  1. /* ARx_MakeNodeList.rexx     Version 2.0    (02 Mar 1994)
  2. **
  3. **        Make an AmigaGuide .xref cross-reference file for all files matching
  4. **    a supplied pattern.
  5. **
  6. **    NOTE TO WShell USERS: Pasted to the bottom of this script is a version
  7. **    that does the same thing but with _far_ more efficiency. It uses WShell's
  8. **    ExecIO utility, though, so those who haven't yet bought WShell can't
  9. **    use it. Moral: If you're going to use ARexx, buy WShell.
  10. */
  11.  
  12. parse arg FPat
  13. if FPat = '' | FPat = '?' then do
  14.     options prompt 'PATTERN/A: '
  15.     parse pull FPat
  16. end
  17. if FPat = '' then exit 0
  18.  
  19. FList = 't:ARx_NFiles'        /* Used for list of files to be processed */
  20. NList = 't:ARx_NodeList'   /* Used for the actual node list          */
  21. File. = ''
  22.  
  23. NPath = ParseFileName(FPat, 'P')
  24. if NPath > '' then
  25.     OrgPath = pragma('D', NPath)
  26.  
  27. if verify(FPat, '#?~!()*', 'M') = 0 then do
  28.     File.0 = 1
  29.     File.1 = FPat
  30. end
  31. else do        /* We have a pattern. Use list to expand it */
  32.     address command
  33.     'list quick nohead' FPat 'to' FList
  34.     if exists(FList) & word(statef(FList),2) > 0 then do
  35.         if open(6FList, FList, R) then do
  36.             call delete FList
  37.             do i = 1 until eof(6FList)
  38.                 File.i = readln(6FList)
  39.             end
  40.             call close 6FList
  41.             File.0 = i - 1        /* Last value is always blank */
  42.         end
  43.     end
  44.     else signal NoFile
  45. end
  46.  
  47.     /* We have a list of files, so look for '@node' within each file */
  48.  
  49. NodeList = '01010101010a'x    /* Dummy pattern is replaced after sort with 'XREF:' */
  50. NodeNum = 0                        /* Count extra compound used for long lists     */
  51. do i = 1 to File.0
  52.     say '   Creating node list for file' File.i
  53.     FNOnly = ParseFileName(File.i)
  54.     PrgMsg = '      Reading file ...'
  55.     if open(6Input, File.i, 'R') then do until eof(6Input)
  56.         call writech(STDOUT, PrgMsg)
  57.             /* Read the whole file at once -- or as much of it as we can get. **
  58.             ** Concatenate FText in case previous read broke it in the middle **
  59.             ** of node reference.                                             */
  60.         FText = FText || upper(readch(6Input, 65532-length(FText)))
  61.             /* Look for '@NODE' in the file variable                          */
  62.         do until pos('@NODE', FText) = 0
  63.             parse var FText . '@NODE ' NName FText
  64.                     /* If the node name is quoted, check for multiple words     */
  65.             if pos('"', NName) then do
  66.                 parse var FText NName2 '"' FText
  67.                 NName = '"'NName || NName2'"'
  68.             end
  69.                 /* Cut off name from other line if there's nothing else on line */
  70.             parse var NName NName '0a'x .
  71.             if NName ~= 'MAIN' & NName > '' then
  72.                 NodeList = NodeList || left(NName, 18) '"'FNOnly'" 0 0' || '0a'x
  73.                 /* Split the list if it's getting too big */
  74.             if i < File.0 & length(NodeList) >= 64000 then do
  75.                 /* The var [NodeList] is different than the stem [NodeList.]   */
  76.                 NodeNum = NodeNum + 1
  77.                 NodeList.NodeNum = NodeList
  78.                 NodeList = ''
  79.             end
  80.         end
  81.         PrgMsg = '..'
  82.             /* There's a small chance that a _very_ long node would leave so  **
  83.             ** so much in [FText] that we'd never get out of the node. This   **
  84.             ** prevents that by chopping off text that doesn't include the    **
  85.             ** start of an AG label of some kind.                             */
  86.         if pos('0a'x||'@', FText) = 0 then FText = ''
  87.         else FText = substr(FText,pos('0a'x||'@', FText))
  88.     end
  89.     else say 'Can''t open file' File.i
  90.     call close 6Input
  91.     say ''
  92. end
  93.  
  94. if length(NodeList) > 10 | NodeNum > 0 then do
  95.     if open(6Output, NList'.pre', 'W') then do
  96.         say 'Sorting node list'
  97.         do i = 1 to NodeNum
  98.             call writech(6Output, NodeList.i)
  99.         end
  100.         call writech(6Output, Nodelist)
  101.         call close 6Output
  102.     end
  103.     else
  104.     signal NoOutput
  105.  
  106.     'sort from' NList'.pre to' NList
  107.     if rc = 0 then do
  108.         call delete NList'.pre'
  109.         if open(6List, NList, 'R') then do
  110.             call writech(6List, 'XREF:')
  111.             call seek(6List, 0, 'E')
  112.             call writeln(6List, '#')
  113.             call close 6List
  114.         end
  115.     end
  116.     say 'Cross-ref file for' FPat 'created.'
  117.     say '   Saved to file' NList
  118. end
  119.  
  120.  
  121. exit 0
  122.  
  123. NoFile:
  124.     say 'No files match the pattern "'FPat'".'
  125.     exit 5
  126.  
  127. NoOutput:
  128.     say 'Can''t open file' NList' for output.'
  129.     exit 5
  130.  
  131. ParseFileName: procedure
  132.    /* Arguments:                                                     **
  133.    ** FilePath   := Any valid AmigaDOS file specification            **
  134.    ** Part       := [Optional] 'F', 'FILE', or omit to get filename  **
  135.    **                          Anything else to retrieve the path    */
  136.    parse arg FilePath, Part
  137.  
  138.    DivPos = max(lastpos(':', FilePath),lastpos('/', FilePath)) +1
  139.    if abbrev('FILE', upper(Part))
  140.       then return substr(FilePath, DivPos)
  141.    else
  142.       return strip(left(FilePath, DivPos-1),'T', '/')
  143.  
  144. /* ARx_MakeNodeList.rexx     Version 1.3    (21 Aug 93)
  145. **
  146. **        Make an AmigaGuide .xref cross-reference file for all files matching
  147. **    a supplied pattern.
  148. **
  149. **    Uses WShell ExecIO utility.
  150. */
  151.  
  152.  
  153. nodeFN = 't:NodeList'
  154. parse arg FilePat
  155. if FilePat = '' then
  156.     FilePat = '(arexxguide.guide|arx#?.ag)'
  157.  
  158. NPath = ParseFileName(FPat, 'P')
  159. if NPath > '' then
  160.     OrgPath = pragma('D', NPath)
  161.  
  162. 'list quick nohead' FilePat 'lformat "execio read %s stem Nodes. locate *"@node*" colend 5" | execio stem FileCmd.'
  163. call open(NodeFile, NodeFN ,w)
  164. call writeln(NodeFile, '!!!!'||'0a'x)
  165. do i = 1 to FileCmd.0
  166.     File = word(FileCmd.i, 3)
  167.     say '   Reading file' File
  168.     select
  169.         when pos('FUNC', upper(File)) > 0 then Type = '0 1'
  170.         when pos('INSTR', upper(File)) > 0 then Type = '0 2'
  171.         otherwise Type = '0 0'
  172.     end
  173.     FileCmd.i    /* this is a command to AmigaDOS */
  174.     do j = 1 to Nodes.0
  175.         node = word(Nodes.j, 2)
  176.         if upper(node) ~= 'MAIN' & ~abbrev(upper(node), 'ABOUT') then
  177.             call writeln(NodeFile, left(Node, 24) '"'File'"' Type)
  178.     end
  179. end
  180.  
  181. call close NodeFile
  182. call delete(NodeFN'.sort')
  183. address command 'sort' nodeFN nodeFN'.sort'
  184. if open(NodeStart, NodeFN'.sort', R) then do
  185.     call writech(NodeStart, 'XREF:')
  186.     NewPos = seek(NodeStart,0,E)
  187.     call writeln(NodeStart, '#')
  188.     call close NodeStart
  189. end
  190.  
  191.     /*** Include the ParseFileName() function            ***/